package cn.yunhe.service;

import cn.yunhe.dao.LeaveMessageDao;
import cn.yunhe.entity.LeaveMessage;
import cn.yunhe.entity.Page;
import cn.yunhe.entity.leaveMess;
import cn.yunhe.util.PageUtil;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class LeaveMessageService  {
    SqlSession sqlSession = SqlSessionFactoryUtil.getSession();
    LeaveMessageDao leaveMessageDao = sqlSession.getMapper(LeaveMessageDao.class);

    public Boolean addLeaveMessage(LeaveMessage leaveMessage) {
        Boolean b = leaveMessageDao.addLeaveMessage(leaveMessage);
        sqlSession.commit();
        sqlSession.close();
        return b;
    }
    public List<LeaveMessage> getLeaveMessage(int currPage) {

        Page page=new Page();
        page.setPageStart(PageUtil.PAGE_SIZE * (currPage - 1));   //pageSize*(currPage-1)
        page.setPageSize(PageUtil.PAGE_SIZE);
        List<LeaveMessage> leaveMessageList=leaveMessageDao.getLeaveMessage(page);
        return leaveMessageList;
    }

    public boolean delLeaveMessageByNewsid(int leaveId) {
        boolean flag=leaveMessageDao.delLeaveMessageByNewsid(leaveId);
        sqlSession.commit();
        return flag;
    }

    public boolean updateLeavemessage(leaveMess leavem) {
        boolean flag=leaveMessageDao.updateLeavemessage(leavem);
        sqlSession.commit();
        return flag;
    }

    public int getleaveMessageDaoCount() {
        return leaveMessageDao.getleaveMessageDaoCount();
    }
}
